package com.lyy.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lyy.common.utils.UUIDUtils;
import com.lyy.project.dao.ProProjectGlobalDao;
import com.lyy.project.pojo.ProProjectGlobal;
import com.lyy.project.service.ProProjectGlobalService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 项目全局设置(ProProjectGlobal)表服务实现类
 *
 * @author Yw
 * @since 2021-02-01 17:22:31
 */
@Service
public class ProProjectGlobalServiceImpl extends ServiceImpl<ProProjectGlobalDao, ProProjectGlobal> implements ProProjectGlobalService {


    /**
     * 添加项目全局设置
     *
     * @param proProjectGlobal
     */
    @Override
    public void createProProjectGlobal(ProProjectGlobal proProjectGlobal) {
        baseMapper.insert(proProjectGlobal);
    }

    /**
     * 根据主键修改项目全局设置
     *
     * @param proProjectGlobal
     */
    @Override
    public void updateProProjectGlobal(ProProjectGlobal proProjectGlobal) {
        baseMapper.update(proProjectGlobal, new UpdateWrapper<ProProjectGlobal>()
                .eq("id", proProjectGlobal.getId())
        );
    }

    /**
     * 根据主键删除项目全局设置
     *
     * @param id
     * @return
     */
    @Override
    public void deleteProProjectGlobal(ProProjectGlobal proProjectGlobal) {
        baseMapper.delete(new UpdateWrapper<ProProjectGlobal>()
                .eq("id", proProjectGlobal.getId())
        );
    }

    /**
     * 根据主键查询项目全局设置详情
     *
     * @param id
     * @return
     */
    @Override
    public ProProjectGlobal getProProjectGlobal(ProProjectGlobal proProjectGlobal) {
        return baseMapper.selectOne(new QueryWrapper<ProProjectGlobal>()
                .eq("id", proProjectGlobal.getId())
        );
    }

    /**
     * 批量添加项目全局设置
     *
     * @param proProjectGlobals
     */
    @Override
    public int batchInsert(List<ProProjectGlobal> proProjectGlobals) {
        return baseMapper.batchInsert(proProjectGlobals);
    }


    /**
     * 批量修改项目全局设置
     *
     * @param proProjectGlobals
     */
    @Override
    public int batchUpdate(List<ProProjectGlobal> proProjectGlobals) {
        return baseMapper.batchUpdate(proProjectGlobals);
    }

    /**
     * 查询项目全局设置列表
     *
     * @param proProjectGlobal
     */
    @Override
    public List<ProProjectGlobal> selectProProjectGlobalList(ProProjectGlobal proProjectGlobal) {
        return baseMapper.selectProProjectGlobalList(proProjectGlobal);
    }

    /**
     * 查询项目全局设置数量
     *
     * @param proProjectGlobal
     */
    @Override
    public int selectProProjectGlobalCount(ProProjectGlobal proProjectGlobal) {
        return baseMapper.selectProProjectGlobalCount(proProjectGlobal);
    }


    /**
     * 导入项目全局设置excel
     *
     * @param proProjectGlobals
     */
    @Override
    public List<Map<String, String>> importProProjectGlobalExcel(List<ProProjectGlobal> proProjectGlobals) {
        List<Map<String, String>> mapList = new ArrayList<>();
        proProjectGlobals.forEach(proProjectGlobal -> {
            proProjectGlobal.setId(UUIDUtils.getUUIDTWO());
            Map<String, String> map = new HashMap<>();
            map.put("status", "0");
            map.put("reason", "导入成功");
            mapList.add(map);
        });
        batchInsert(proProjectGlobals);
        return mapList;
    }
}